package com.caocaog.market.finance.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.finance.entity.MkBillBase;
import com.caocaog.market.finance.entity.MkBillHistory;
import com.caocaog.market.finance.entity.MkBillLine;
import com.caocaog.market.finance.entity.MkBillLineHistory;
import com.caocaog.market.finance.vo.SysCheckVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author liguang
 * @version 1.0.0
 * @Project jeecg-boot
 * @Package com.caocaog.market.finance.mapper
 * @ClassName MkBillLineMapper.java
 * @createTime 2021年12月03日 19:22:00
 * @Description TODO
 */
public interface MkBillLineMapper extends BaseMapper<MkBillLine> {
    /**
     * 分页查询
     */
    IPage<MkBillLine> findForPage(Page<MkBillLine> page, MkBillLine billLine);


    @Select(value = "SELECT audit_no AS auditNo , COUNT(audit_no) as num FROM  mk_bill_line WHERE withdraw_cash_status =2 GROUP BY audit_no")
    List<SysCheckVo> findSysCheckVoList();

    /**
     * 不分页
     */
    List<MkBillLine> findForPage(@Param("billLine") MkBillLine billLine);


    List<MkBillLine> findByChange(@Param("billLineChange") MkBillLine billLine);

    /**
     * 分站/商家发起提现申请
     *   有两个操作：
     *      1、更新mk_bill_line表的提现状态
     *      2、向mk_bill_line_history表中插入一条记录
     */
    @Insert({"INSERT INTO mk_bill_change (create_by,update_by,bill_base_id,bill_line_id,`status`,type,change_no)" +
            "SELECT 1 as create_by,1 as update_by,bill_base_id,id as bill_line_id,1 as status,2 as type,'123456' as change_no" + "FROM mk_bill_line WHERE order_no in ('20220104153944920350321','20220104161332488125331') and type = 2"})
    int applyForWithdrawCash(MkBillLine line);

    int dealWithdrawCashApplication(@Param("billLineHistories") List<MkBillLineHistory> billLineHistories);


    /**
     * 系统对提现申请进行审核
     */
//    int check

    /**
     * 批量修改订单状态
     */
//    Integer updateStatusById(@Param("idList") List<String> idList, @Param("newStatus") Integer newStatus);

    //List<MkBillLine> selectBatchIds(List<Object> idList);
}
